import { defineStore } from "pinia";
interface GoodsType {
  name: string;
  price: number;
}
export const useGoods = defineStore("goods", {
  state: () => ({
    list: [
      { name: "苹果", price: 10 },
      { name: "耙耙柑", price: 5 },
      { name: "香蕉", price: 8 },
    ],
  }),
  getters: {
    // 写法1:自动推断类型
    // filterList(state) {
    //   return state.list.filter((item) => item.price > 60);
    // },
    //写法2：必须注明类型
    filterList(): GoodsType[] {
      return this.list.filter((item) => item.price > 60);
    },
  },
  persist: {
    key: "goods-2302", //开启持久化，并未数据包命名
  },
});
